package com.yanqu.road.server.cmd.activity.doublespring.cross;

import com.yanqu.road.entity.activity.doublespring.DoubleSpringActivityConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.DoubleSpringProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.PreReduceModule;
import com.yanqu.road.server.manger.activity.doublespring.DoubleSpringActivityMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

@Cmd(code = Protocol.S_DOUBLE_SPRING_TRAVEL_FROM_CROSS,desc = "踏春游记-跨服返回-出行")
public class DoubleSpringTravelFromCrossCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        DoubleSpringProto.DoubleSpringCrossTravelMsg reqMsg = DoubleSpringProto.DoubleSpringCrossTravelMsg.parseFrom(packet.getBytes());
        //撤销预扣道具
        DoubleSpringActivityConfig config = DoubleSpringActivityMgr.getActivityConfig(reqMsg.getActivityId());
        if (config == null) {
            return;
        }
        DoubleSpringProto.DoubleSpringTravelRespMsg.Builder respMsg = DoubleSpringProto.DoubleSpringTravelRespMsg.newBuilder();
        //撤销预扣除道具
        player.getModule(PreReduceModule.class).restorePreReduce(config.getDoubleSpringItemCost());
        if (reqMsg.getRet() > 0) {
            respMsg.setRet(reqMsg.getRet());
        } else {
            //出行处理
            String reward = DoubleSpringActivityMgr.travelCrossHandle(player, reqMsg.getActivityId(), reqMsg.getTotalScore(), reqMsg.getPartnerUserId(), reqMsg.getAddScore());
            respMsg.setRet(0);
            respMsg.setScore(reqMsg.getScore());
            respMsg.setTotalScore(reqMsg.getTotalScore());
            respMsg.setReward(reward);
        }
        player.sendPacket(Protocol.U_DOUBLE_SPRING_TRAVEL, respMsg);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
